<?php
include("header.php");

$disciplineID = $_GET["id"];
$collegeID = $_GET["college"];
$term = $_GET["term"];

if($collegeID){
        if($collegeID > 0){
        	$sql = "SELECT classID as id, longName as name FROM (classes JOIN classes_info ON classes_classID = classID) JOIN discipline ON discipline.discID=discipline_discID WHERE college_collegeID=$collegeID";
        }
        else{
                $sql = "SELECT classID as id, longName as name FROM (classes JOIN classes_info ON classes_classID = classID) JOIN discipline ON discipline.discID=discipline_discID WHERE college_collegeID > 0";
        }
}
if($disciplineID){

    	$sql = "SELECT c.classID as id, ci.longName as name FROM classes AS c JOIN classes_info AS ci ON ci.classes_classID = c.classID JOIN terms AS t ON t.classes_classID = c.classID WHERE c.discipline_discID = $disciplineID AND t.quarter = '$term'";
}

$sql .=  " ORDER BY name ASC";

$r = mysql_query($sql, $con);

$classes = array();
if(mysql_num_rows($r)) {
	while($class = mysql_fetch_assoc($r)) {
		$classes[] = $class;
	}
}

header('Content-type: application/json');
echo json_encode(array('classes'=>$classes));
//echo json_encode($classes);

include("footer.php");
?>
